//
//  HMTabBarController.swift
//  HMSlender
//
//  Created by 赵少朋赵少朋 on 17/1/16.
//  Copyright © 2017年 ITheima. All rights reserved.
//

import UIKit

class HMTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tabBar = HMTabBar()
        //实例化闭包
        tabBar.closure = { ()->() in
        
//            print("撰写按钮点击了")
            //实例化compose视图对象
            let composeView = HMComposeView()
            
            composeView.showView(target: self)
        }
        
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(viewCt: HMHomeController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(viewCt: HMMessageController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(viewCt: HMDiscoverController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(viewCt: HMProfileController(), title: "我的", imgName: "tabbar_profile")
        
    }
    
    func addChildViewController(viewCt:UIViewController ,title:String , imgName:String) {
        

        viewCt.navigationItem.title = title
        viewCt.tabBarItem.title = title
        
        viewCt.tabBarItem.image = UIImage(named: imgName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        viewCt.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        let navCt = HMNavigationController(rootViewController: viewCt)
        addChildViewController(navCt)
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
